package com.tsll.controller;

import com.tsll.entity.Staff;
import com.tsll.service.MenuService;
import com.tsll.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;
    @Autowired
    private HttpSession session;
    /**
     * 获取菜单信息。
     * @return Result
     */
    @GetMapping("/leftMenu")
    public Result leftMenu(){
        Staff staff = (Staff) session.getAttribute("staff");
        // 根据staff的id查询其对应的菜单信息
        Result result = menuService.findByStaffId(staff.getId());
        
        return result;
    }

    /**
     *
     * @param roleId
     * @return
     */
    @GetMapping("getByRoleId")
    public Result getByRoleId(Integer roleId){
        return menuService.findByRoleId(roleId);
    }

    /**
     *
     * @param roleId
     * @param menuIds
     * @return
     */
    @GetMapping("/confirmUpdate")
    public Result confirmUpdate(Integer roleId,Integer[] menuIds){
        return menuService.confirmUpdate(roleId,menuIds);
    }
}
